﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Data;
using System.Data.Linq;
using System.Data.Linq.Mapping;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Data.SqlTypes;

public class CustomRow
{
    //din aspnet_User
    public string UserName { get; set; }
    //din Bookmark
    public decimal Index { get; set; }
    public string Titlu { get; set; }
    public string Owner { get; set; }
    public string Descriere { get; set; }
    public string Taguri { get; set; }
    public System.Nullable<int> Voturi { get; set; }
    //din Comments
    public string Message { get; set; }
}

public partial class _Default : System.Web.UI.Page
{
    static string vun;
    
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected string getUserid(string x)
    {
        DataContext db = new DataContext("Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\ASPNETDB.MDF;Integrated Security=True;User Instance=True;");
        Table<aspnet_User> aspnet_Users = db.GetTable<aspnet_User>();
        Decimal URIvar = System.Convert.ToDecimal(Request["id"]);
        IQueryable<CustomRow> BookmarkQuery = from s in aspnet_Users
                                              where s.UserName == x
                                              select new CustomRow { Owner = s.UserId };
        String y = "";
        foreach (CustomRow i in BookmarkQuery)
        {
            y= i.Owner;
        }
        return y;
    }
    protected void f2(object sender, EventArgs e)
    {
        vun = ((TextBox)sender).Text;
    }
    protected void f1(object sender, EventArgs e)
    {
            
    }
    protected void ContinueButton_Click(object sender, EventArgs e)
    {
        String sql = "INSERT INTO aspnet_UsersInRoles (UserId,RoleId) VALUES (@user,@ID)";
        String GuidVal = "08b44f1e-0bda-403e-8610-4fbbb1e4c2ca";
        SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\ASPNETDB.MDF;Integrated Security=True;User Instance=True");
        SqlCommand cmd = new SqlCommand(sql, con);

        cmd.Parameters.AddWithValue("@user", getUserid(vun));
        cmd.Parameters.AddWithValue("@ID", GuidVal);

        con.Open();
        cmd.ExecuteNonQuery();
        con.Close();
        Server.Transfer("index.aspx");

    }
}
